package org.example;

import java.time.LocalDate;
import java.util.*;

public class MetroStation implements Comparable<MetroStation> {
    private final String name;
    private final String lineNumber;
    private LocalDate date;
    private Double depth;
    private final Set<MetroStation> connections = new HashSet<>();

    public MetroStation(String name, String lineNumber) {
        this.name = name;
        this.lineNumber = lineNumber;
    }

    public static String getID(String name, String lineNumber) {
        return name + "@" + lineNumber;
    }

    public String getID() {
        return getID(name, lineNumber);
    }

    public String getName() {
        return name;
    }

    public String getLineNumber() {
        return lineNumber;
    }

    public LocalDate getDate() {
        return date;
    }

    public void setDate(LocalDate date) {
        this.date = date;
    }

    public Double getDepth() {
        return depth;
    }

    public void setDepth(Double depth) {
        this.depth = depth;
    }

    public Collection<MetroStation> getConnections() {
        return new ArrayList<>(connections);
    }

    public boolean addConnection(MetroStation station) {
        if (station == null) {
            return false;
        }
        return connections.add(station);
    }

    public boolean isConnected(MetroStation station) {
        return connections.contains(station);
    }

    public boolean hasConnection() {
        return !connections.isEmpty();
    }

    public String toString() {
        StringJoiner stringJoiner = new StringJoiner(System.lineSeparator());

        stringJoiner.add(getID() + " " + getDate() + " " + getDepth());

        for (MetroStation station : getConnections()) {
            stringJoiner.add("\t" + station.getID());
        }

        return stringJoiner.toString();
    }

    @Override
    public int compareTo(MetroStation o) {
        return getID().compareTo(o.getID());
    }
}
